class Solution {
public:
    //https://leetcode.cn/problems/replace-all-s-to-avoid-consecutive-repeating-characters/
    string modifyString(string s) 
    {
        int n = s.size();
        for(int i = 0; i < n; i++)
        {
            char c = 'a';
            while(s[i] == '?')
            {
                if((i == 0 || s[i - 1] != c) && (i == n - 1 || s[i + 1] != c))//这里需要注意对细节的把控
                s[i] = c;
                c++;
            }
        }
        return s;
    }

    //https://leetcode.cn/problems/teemo-attacking/
    int findPoisonedDuration(vector<int>& timeSeries, int duration) 
    {
        int sum = 0;
        int size = timeSeries.size();
        for(int i = 0; i < size; i++)
        {
            if(i != size - 1 )
            sum += min(duration, timeSeries[i + 1] - timeSeries[i]);
            else sum += duration;
        }
        return sum;
    }

    //https://leetcode.cn/problems/zigzag-conversion/
    string convert(string s, int numRows) 
    {
        if(numRows == 1) return s;
        string str;
        int d = 2 * numRows - 2;
        for(int i = 0; i < s.size(); i += d)//注意细节循环分开来写
        {
            str += s[i];
        }
        for(int i = 1; i < numRows - 1; i++)
        {
            for(int k = i, j = d - i; k < s.size() || j < s.size(); k += d, j += d)
            {
                if(k < s.size()) str += s[k];
                if(j < s.size()) str += s[j];
            }
        }
        for(int i = numRows - 1; i < s.size(); i += d)
        {
            str += s[i];
        }
        return str;
    }
};